<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/commons/global.jsp"%>

<div id="categoryAddDiv" class="easyui-window" title="添加分类"
	style="width: 400px; height: 300px"
	data-options="iconCls:'icon-cog',modal:true,openAnimation:'fade',closeAnimation:'slide',cache:false,collapsible:false,minimizable:false,maximizable:false">
	<div class="content-wrapper">
		<form id="categoryAddForm" method="post" style="padding: 10px;">
			<input id="categoryAddForm-name" type="text" name="name"
				style="width: 100%;" /> <input id="categoryAddForm-sort"
				name="sort" style="width: 100%;" value="0" /> <input
				id="categoryAddForm-itemType" name="itemType" style="width: 100%;" />
			<input id="categoryAddForm-parentId" name="parentId"
				style="width: 100%;" /> <input name="entity" style="display: none;"
				value="1" /> <input type="button" value="添  加"
				onclick="$('#categoryAddForm').submit();"
				style="float: right; margin-top: 10px;" />
			<div style="clear: both;"></div>
		</form>
	</div>
</div>

<script type="text/javascript">
	var categoryAddForm_itemType = undefined;
	var categoryAddForm_parentId = undefined;
	var categoryAddForm_sort = undefined;
	var categoryAddForm_name = undefined;
	$(function() {

		categoryAddForm_sort = $('#categoryAddForm-sort').numberbox({
			buttonText : '排&nbsp;&nbsp;&nbsp;&nbsp;序',
			buttonAlign : 'left',
			precision : 2
		});

		categoryAddForm_parentId = $('#categoryAddForm-parentId').combobox({
			buttonText : '所&nbsp;属&nbsp;分类',
			buttonAlign : 'left',
			data : [ {
				id : 0,
				text : '全部分类集合',
				selected : true
			} ],
			valueField : 'id',
			textField : 'text'
		});

		categoryAddForm_itemType = $('#categoryAddForm-itemType')
				.combobox(
						{
							buttonText : '所属资源类型',
							buttonAlign : 'left',
							valueField : 'id',
							textField : 'text',
							data : [ {
								"id" : 0,
								"text" : "全部资源类型",
								"selected" : true
							}, {
								"id" : 1,
								"text" : "视频"
							}, {
								"id" : 2,
								"text" : "音频"
							}, {
								"id" : 3,
								"text" : "文本"
							} ],
							onChange : function(newValue, oldValue) {
								if (newValue && newValue != '0') {
									categoryAddForm_parentId.combobox('reload',
											baseUrl + '/category/list/top/'
													+ newValue);
								} else {
									categoryAddForm_parentId
											.combobox('options').data = [ {
										parentId : 0,
										text : '全部分类集合',
										selected : true
									} ];
								}

							}
						});

		categoryAddForm_name = $('#categoryAddForm-name').textbox({
			buttonText : '名&nbsp;&nbsp;&nbsp;&nbsp;称',
			buttonAlign : 'left'
		});

		var categoryAddDiv = $('#categoryAddDiv').window({
			onBeforeClose : function() {

			},
			onClose : function() {
				categoryAddDiv.panel('destroy');
				try {
					categoryListDatagrid.datagrid('reload');
				} catch (e) {
				}
			}
		});

		$('#categoryAddForm').form({
			url : baseUrl + '/category/add',
			onSubmit : function() {
				var name = categoryAddForm_name.textbox('getValue');
				var itemType = categoryAddForm_itemType.combobox('getValue');
				var parentId = categoryAddForm_parentId.combobox('getValue');
				// 				var sort = categoryAddForm_sort.numberbox('getValue');

				if (!name) {
					$.messager.alert('提示', '请输入名称', 'warning');
					return false;
				}
				if (!itemType || itemType == '0') {
					$.messager.alert('提示', '请选择所属资源类型', 'warning');
					return false;
				}
				if (!parentId || parentId == '0') {
					$.messager.alert('提示', '请选择所属分类', 'warning');
					return false;
				}
			},
			success : function(data) {
				data = eval("(" + data + ")");
				if (data.responseCode == '000') {
					$.messager.alert('提示', '添加成功!', 'info');
				} else {
					$.messager.alert('提示', data.responseMessage, 'error');
				}
			}
		});

	});
</script>